package cl.uchile.sti.authorization.dao;

import cl.uchile.sti.authorization.model.Permiso;
import cl.uchile.sti.authorization.model.Rol;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Julio Villane
 * Date: 11-12-12
 * Time: 12:34 PM
 */
public class PermisoDAO {

    private static EntityManager entityManager = cambiarPorSpring.getEntityManager();

    private PermisoDAO(){ }

    public static List<Permiso> find(){
        Query q =  entityManager.createQuery("select p from Pagina p ");
        List <Permiso> resultado=q.getResultList();
        return resultado;
    }
    public static Permiso findID(Long id){
        return entityManager.find(Permiso.class, id);
    }
    public static Permiso findActive(Long active){
        return entityManager.find(Permiso.class, active);
    }
    public static Permiso findNombre(Long nombre){
        return entityManager.find(Permiso.class, nombre);
    }
    public static Permiso findModulo(Long modulo){
        return entityManager.find(Permiso.class, modulo);
    }

    public static Permiso save(Permiso permiso) {

        if (permiso.getId() == null) {
            entityManager.persist(permiso);
            return permiso;
        } else {
            return entityManager.merge(permiso);
        }
    }


}
